#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>

int main(int argc,char* argv[],char* env[])
{
    pid_t id=fork();
    if(id==0)
    {
        //子进程
        printf("子进程开始运行，pid:%d\n",getpid());
        sleep(3);

        char* const _argv[]={
           (char*) "ls",
           (char*) "-a",
           (char*) "-l",
            NULL
        };
        
        char* const _argv_mycmd[]={(char*)"mycmd",(char*)"-a",NULL};
        char* const _env_mycmd[]={(char*)"My_Path=11111",NULL};
       // execl("/usr/bin/ls","ls","-a","-l",NULL);
       // execv("/usr/bin/ls",_argv);
       // execlp("ls","ls","-a","-l",NULL);
       // execle("/usr/bin/ls","ls","-a","-l",NULL,env);
       // execle("./mycmd","mycmd","-a",NULL,_env);
       // execvp("ls",_argv);
       // execvpe("ls",_argv,env);
       // execve("./mycmd",_argv_mycmd,_env_mycmd);

       // execlp("bash","bash","test.sh",NULL);
       // execlp("python","python","test.py",NULL);
       // execlp("./test.py","test.py",NULL);
       // execlp("./test.sh","test.sh",NULL);
        exit(1);
    }
    else
    {
        //父进程
        printf("父进程开始运行，pid:%d\n",getpid());
        int status=0;
        pid_t id=waitpid(-1,&status,0);//阻塞等待
        if(id>0)
        {
            printf("wait seccess,exit code:%d\n",WEXITSTATUS(status));
        }
    }
    return 0;
}
